package com.zhf.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler;
import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException;
import org.springframework.stereotype.Service;

@Service(value = "RabbitConsumerListenerErrorHandler")
public class RabbitConsumerListenerErrorHandler implements RabbitListenerErrorHandler {

    private static final Logger logger = LoggerFactory.getLogger(RabbitConsumerListenerErrorHandler.class);

    @Override
    public Object handleError(Message amqpMessage, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException exception) throws Exception {
        logger.error("error consuming message: {}", amqpMessage.getMessageProperties().getConsumerQueue());
        return exception;
    }
}
